<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="院校名称" prop="schoolName">
        <el-input
          v-model="queryParams.schoolName"
          placeholder="请输入院校名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标签" prop="typeIds">
        <el-select v-model="queryParams.typeIds" filterable clearable placeholder="请选择标签" size="small" @change="handleQuery">
          <el-option
            v-for="item in schoolType"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="院校编码" prop="schoolCode">
        <el-input
          v-model="queryParams.schoolCode"
          placeholder="请输入院校编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在省份" prop="provinceName">
        <el-select v-model="queryParams.provinceName" filterable clearable size="small" placeholder="请选择所在省份" @change="handleQuery">
          <el-option
            v-for="item in provinceName"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="办学层次" prop="uOrS">
        <el-select v-model="queryParams.uOrS" clearable size="small" placeholder="请选择本科专科" @change="handleQuery">
          <el-option
            v-for="item in education"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="toAdd"
          v-hasPermi="['system:CompassUniversityInfo:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <importData
          v-hasPermi="['system:CompassUniversityInfo:edit']"
          title="院校数据"
          action="CompassUniversityInfo"
          @success="getList"
        >
        </importData>
      </el-col>
      <el-col :span="1.5">
        <importData
          v-hasPermi="['system:CompassUniversityInfo:edit']"
          title="招生简章"
          action="CompassAdmissionsGuide"
        >
        </importData>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:CompassUniversityInfo:remove']"
        >删除
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:CompassUniversityInfo:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="CompassUniversityInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="中文名字" align="center" prop="schoolName">
        <template #default="{row}">
          <el-image :src="row.imgUrl"
                    fit="cover"
                    style="width: 40px; height: 40px">
            <div slot="error" class="image-slot">
              <div>
                <i class="el-icon-picture-outline" style="font-size: 40px"></i>
              </div>
            </div>
          </el-image>
          <div>{{row.schoolName}}</div>
        </template>
      </el-table-column>
      <el-table-column label="院校编码" align="center" prop="schoolCode"/>
      <el-table-column label="排名" align="center" prop="schoolRank"/>
      <el-table-column label="办学层次" align="center" prop="uorS"/>
      <el-table-column label="学校类型" align="center" prop="schoolType"/>
      <el-table-column label="所在省份" align="center" prop="provinceName"/>
      <el-table-column label="地址" align="center" prop="schoolAddress"/>
      <el-table-column label="所属机构" align="center" prop="agencyName"/>
      <!--<el-table-column label="院校介绍" align="center" prop="schoolDesc"/>-->
      <el-table-column label="简单标签" align="center" prop="typeIds"/>


      <!--<el-table-column label="困难生资助办法" align="center" prop="difficultStudent"/>
      <el-table-column label="对往届生的录取政策" align="center" prop="pastStudents"/>-->
      <!--<el-table-column label="食堂情况" align="center" prop="diningHall"/>
      <el-table-column label="学校环境" align="center" prop="schoolCondition"/>-->
      <!--<el-table-column label="图片ID" align="center" prop="imgId"/>-->
      <el-table-column label="招办电话" align="center" prop="recruitTel"/>
      <el-table-column label="博士点" align="center" prop="doctorPoint"/>
      <el-table-column label="硕士点" align="center" prop="masterPoint"/>
      <!--<el-table-column label="对艺术类招生的录取办法" align="center" prop="artAdmissions"/>
      <el-table-column label="奖学金介绍" align="center" prop="scholarship"/>
      <el-table-column label="对少数民族考生的特色政策" align="center" prop="minorityCandidates"/>
      <el-table-column label="宿舍情况" align="center" prop="hostelDesc"/>
      <el-table-column label="学校领导" align="center" prop="schoolLeader"/>-->
      <el-table-column label="官网" align="center" prop="officialWeb"/>

      <!--<el-table-column label="转专业的实施办法" align="center" prop="changeMajor"/>
      <el-table-column label="录取批次安排" align="center" prop="admissionBatch"/>
      <el-table-column label="平均伙食标准" align="center" prop="foodStandard"/>
      <el-table-column label="加分政策" align="center" prop="bonusPolicy"/>-->
      <!--<el-table-column label="院系设置" align="center" prop="facultySetting"/>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="toAdd(scope.row, true)"
            v-hasPermi="['system:CompassUniversityInfo:edit']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="toAdd(scope.row)"
            v-hasPermi="['system:CompassUniversityInfo:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:CompassUniversityInfo:remove']"
          >删除
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-postcard"
            @click="toGuide(scope.row)"
          >招生简章
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改高等院校数据表对话框 -->
    <el-drawer
      :title="title"
      size="50%"
      direction="rtl"
      :visible.sync="open">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="地址" prop="schoolAddress">
          <el-input v-model="form.schoolAddress" placeholder="请输入地址"/>
        </el-form-item>
        <el-form-item label="院校介绍" prop="schoolDesc">
          <el-input v-model="form.schoolDesc" placeholder="请输入院校介绍"/>
        </el-form-item>
        <el-form-item label="简单标签" prop="typeIds">
          <el-input v-model="form.typeIds" placeholder="请输入简单标签"/>
        </el-form-item>
        <el-form-item label="排名" prop="schoolRank">
          <el-input v-model="form.schoolRank" placeholder="请输入排名"/>
        </el-form-item>
        <el-form-item label="院校编码" prop="schoolCode">
          <el-input v-model="form.schoolCode" placeholder="请输入院校编码"/>
        </el-form-item>
        <el-form-item label="困难生资助办法" prop="difficultStudent">
          <el-input v-model="form.difficultStudent" placeholder="请输入困难生资助办法"/>
        </el-form-item>
        <el-form-item label="对往届生的录取政策" prop="pastStudents">
          <el-input v-model="form.pastStudents" placeholder="请输入对往届生的录取政策"/>
        </el-form-item>
        <el-form-item label="食堂情况" prop="diningHall">
          <el-input v-model="form.diningHall" placeholder="请输入食堂情况"/>
        </el-form-item>
        <el-form-item label="学校环境" prop="schoolCondition">
          <el-input v-model="form.schoolCondition" placeholder="请输入学校环境"/>
        </el-form-item>
        <el-form-item label="图片ID" prop="imgId">
          <el-input v-model="form.imgId" placeholder="请输入图片ID"/>
        </el-form-item>
        <el-form-item label="招办电话" prop="recruitTel">
          <el-input v-model="form.recruitTel" placeholder="请输入招办电话"/>
        </el-form-item>
        <el-form-item label="博士点" prop="doctorPoint">
          <el-input v-model="form.doctorPoint" placeholder="请输入博士点"/>
        </el-form-item>
        <el-form-item label="所属机构" prop="agencyName">
          <el-input v-model="form.agencyName" placeholder="请输入所属机构"/>
        </el-form-item>
        <el-form-item label="所在省份" prop="provinceName">
          <el-input v-model="form.provinceName" placeholder="请输入所在省份"/>
        </el-form-item>
        <el-form-item label="对艺术类招生的录取办法" prop="artAdmissions">
          <el-input v-model="form.artAdmissions" placeholder="请输入对艺术类招生的录取办法"/>
        </el-form-item>
        <el-form-item label="奖学金介绍" prop="scholarship">
          <el-input v-model="form.scholarship" placeholder="请输入奖学金介绍"/>
        </el-form-item>
        <el-form-item label="对少数民族考生的特色政策" prop="minorityCandidates">
          <el-input v-model="form.minorityCandidates" placeholder="请输入对少数民族考生的特色政策"/>
        </el-form-item>
        <el-form-item label="宿舍情况" prop="hostelDesc">
          <el-input v-model="form.hostelDesc" placeholder="请输入宿舍情况"/>
        </el-form-item>
        <el-form-item label="学校领导" prop="schoolLeader">
          <el-input v-model="form.schoolLeader" placeholder="请输入学校领导"/>
        </el-form-item>
        <el-form-item label="官网" prop="officialWeb">
          <el-input v-model="form.officialWeb" placeholder="请输入官网"/>
        </el-form-item>
        <el-form-item label="本科专科" prop="uOrS">
          <el-select v-model="form.uOrS" placeholder="请选择本科专科">
            <el-option label="请选择字典生成" value=""/>
          </el-select>
        </el-form-item>
        <el-form-item label="硕士点" prop="masterPoint">
          <el-input v-model="form.masterPoint" placeholder="请输入硕士点"/>
        </el-form-item>
        <el-form-item label="学校类型" prop="schoolType">
          <el-input v-model="form.schoolType" placeholder="请输入学校类型"/>
        </el-form-item>
        <el-form-item label="中文名字" prop="schoolName">
          <el-input v-model="form.schoolName" placeholder="请输入中文名字"/>
        </el-form-item>
        <el-form-item label="转专业的实施办法" prop="changeMajor">
          <el-input v-model="form.changeMajor" placeholder="请输入转专业的实施办法"/>
        </el-form-item>
        <el-form-item label="录取批次安排" prop="admissionBatch">
          <el-input v-model="form.admissionBatch" placeholder="请输入录取批次安排"/>
        </el-form-item>
        <el-form-item label="平均伙食标准" prop="foodStandard">
          <el-input v-model="form.foodStandard" placeholder="请输入平均伙食标准"/>
        </el-form-item>
        <el-form-item label="加分政策" prop="bonusPolicy">
          <el-input v-model="form.bonusPolicy" placeholder="请输入加分政策"/>
        </el-form-item>
        <el-form-item label="院系设置" prop="facultySetting">
          <el-input v-model="form.facultySetting" placeholder="请输入院系设置"/>
        </el-form-item>
        <el-form-item label="图片" prop="imgUrl">
          <el-input v-model="form.imgUrl" placeholder="请输入图片"/>
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
  import {
    listCompassUniversityInfo,
    getCompassUniversityInfo,
    delCompassUniversityInfo,
    addCompassUniversityInfo,
    updateCompassUniversityInfo,
    exportCompassUniversityInfo
  } from "@/api/system/CompassUniversityInfo";
  import dictMixins from "@/views/mixins/dictMixins";

  export default {
    name: "CompassUniversityInfo",
    mixins: [dictMixins],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 高等院校数据表表格数据
        CompassUniversityInfoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          typeIds: null,
          schoolCode: null,
          provinceName: null,
          uOrS: null,
          schoolType: null,
          schoolName: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        schoolType: [],
        provinceName: [],
        education: []
      };
    },
    async mounted() {
      this.getList();
      this.schoolType = await this.getDictByTypeName('typeIds')
      this.provinceName = await this.getDictByTypeName('provinceName')
      this.education = await this.getDictByTypeName('education')
    },
    methods: {
      /** 查询高等院校数据表列表 */
      getList() {
        this.loading = true;
        listCompassUniversityInfo(this.queryParams).then(response => {
          this.CompassUniversityInfoList = response.list;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          schoolAddress: null,
          schoolDesc: null,
          typeIds: null,
          schoolRank: null,
          schoolCode: null,
          updateTime: null,
          difficultStudent: null,
          pastStudents: null,
          diningHall: null,
          schoolCondition: null,
          imgId: null,
          recruitTel: null,
          doctorPoint: null,
          agencyName: null,
          provinceName: null,
          id: null,
          artAdmissions: null,
          createTime: null,
          scholarship: null,
          minorityCandidates: null,
          hostelDesc: null,
          schoolLeader: null,
          officialWeb: null,
          uOrS: null,
          masterPoint: null,
          schoolType: null,
          schoolName: null,
          changeMajor: null,
          admissionBatch: null,
          foodStandard: null,
          bonusPolicy: null,
          facultySetting: null,
          imgUrl: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加高等院校数据表";
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getCompassUniversityInfo(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改高等院校数据表";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateCompassUniversityInfo(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addCompassUniversityInfo(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除高等院校数据表编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return delCompassUniversityInfo(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function () {
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有高等院校数据表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function () {
          return exportCompassUniversityInfo(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function () {
        });
      },

      // 到新增页面
      toAdd(row, detail) {
        this.$router.push({
          name: "editSchool",
          query: {
            id: row && row.id,
            detail: detail
          }
        });
      },

      // 导入
      handleUpload() {

      },

      // 招生简章
      toGuide(row) {
        this.$router.push({
          name: "schoolGuide",
          query: {
            id: row && row.id
          }
        })
      }
    }
  };
</script>
<style lang="scss" scoped>

</style>
